﻿package org.xhs.report.common.ui
{
    import baidu.ui.managers.*;
    import baidu.wenku.common.model.*;
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;

    public class ErrorSprite extends Sprite
    {
        protected var _noDocText:TextField;
        protected var _noDocIcon:Sprite;
        protected var storeModel:StoreModel;
        protected var screenModel:ScreenModel;
        protected var loaderInfoVo:LoaderInfoVO;

        public function ErrorSprite()
        {
            this.init();
            return;
        }// end function

        protected function init() : void
        {
            this.loaderInfoVo = InstanceManager.createSingletonInstance(LoaderInfoVO);
            this.storeModel = InstanceManager.createSingletonInstance(StoreModel);
            this.screenModel = InstanceManager.createSingletonInstance(ScreenModel);
            this.screenModel.addEventListener(Event.RESIZE, this.screenResize);
            return;
        }// end function

        protected function screenResize(event:Event) : void
        {
            x = (this.screenModel.stageWidth - width) / 2;
            y = this.screenModel.stageHeight / 2 - 30;
            return;
        }// end function

        public function processNoDoc() : void
        {
            if (!this._noDocIcon)
            {
                this._noDocIcon = new IconError();
            }
            this._noDocIcon.y = (-this._noDocIcon.height) / 2;
            addChild(this._noDocIcon);
            if (!this._noDocText)
            {
                this._noDocText = new TextField();
                this._noDocText.selectable = false;
            }
            this._noDocText.defaultTextFormat = new TextFormat(null, null, null, null, null, null, null, null, "left", null, null, null, 6);
            this._noDocText.text = "文档载入异常\n建议您刷新页面或者下载后查看";
            if (this.storeModel.isStore)
            {
                this._noDocText.text = "文档载入异常\n建议您刷新页面";
            }
            this._noDocText.autoSize = "left";
            this._noDocText.x = this._noDocIcon.x + this._noDocIcon.width + 6;
            this._noDocText.y = (-this._noDocText.height) / 2;
            addChild(this._noDocText);
            this.screenModel.stage.addChild(this);
            x = (this.screenModel.stageWidth - width) / 2;
            y = this.screenModel.stageHeight / 2 - 30;
            return;
        }// end function

        public function processDeletedDoc() : void
        {
            if (!this._noDocIcon)
            {
                this._noDocIcon = new IconError();
            }
            this._noDocIcon.y = (-this._noDocIcon.height) / 2;
            addChild(this._noDocIcon);
            var _loc_1:* = this.loaderInfoVo.docUrl.replace("play", "view");
            if (_loc_1.indexOf("?") > 0)
            {
                _loc_1 = _loc_1.substr(0, _loc_1.indexOf("?"));
            }
            _loc_1 = _loc_1 + ("/" + this.loaderInfoVo.docId);
            if (!this._noDocText)
            {
                this._noDocText = new TextField();
                this._noDocText.autoSize = "center";
                this._noDocText.selectable = false;
            }
            this._noDocText.multiline = true;
            var _loc_2:* = new StyleSheet();
            _loc_2.setStyle("p", {leading:"6"});
            _loc_2.setStyle("a:hover", {textDecoration:"underline", color:"#0000FF"});
            _loc_2.setStyle("a:link", {textDecoration:"none", color:"#0000FF"});
            this._noDocText.styleSheet = _loc_2;
            this._noDocText.htmlText = "<p>对不起，该文档已被删除，无法查看<br>";
            this._noDocText.htmlText = this._noDocText.htmlText + ("试试<font FACE=\'Arial\' COLOR=\'#0000FF\'><a href=\'" + _loc_1 + "\'>点击原文档链接</a></font>，查看相关文档吧</p>");
            this._noDocText.x = this._noDocIcon.x + this._noDocIcon.width + 6;
            this._noDocText.y = (-this._noDocText.height) / 2;
            addChild(this._noDocText);
            this.screenModel.stage.addChild(this);
            x = (this.screenModel.stageWidth - width) / 2;
            y = this.screenModel.stageHeight / 2 - 30;
            return;
        }// end function

    }
}
